package com.qhg.saas_server.controller;

import com.github.pagehelper.PageInfo;
import com.qhg.saas_server.annotation.Mylog;
import com.qhg.saas_server.empty.Result;
import com.qhg.saas_server.pojo.Comployee;
import com.qhg.saas_server.pojo.dto.ComployeeInfoDto;
import com.qhg.saas_server.service.impl.ComployeeServiceImpl;
import lombok.extern.java.Log;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/Comployee")
public class ComployeeController {

    @Autowired
    ComployeeServiceImpl comployeeService;

    @Mylog(value = "在员工表中模糊查询名字和部门")
    @PostMapping("/SelectComployee")
    public Result SelectComployee(Integer pageNum,Integer pageSize, String comploName, String departName){
        PageInfo pageInfo = comployeeService.SelectComployee(pageNum,pageSize, comploName, departName);
        return Result.success(pageInfo);
    }
    @PostMapping("/SelectRComployee")
    public Result SelectRComployee(Integer pageNum,Integer pageSize, String comploName, String departName){
        PageInfo pageInfo = comployeeService.SelectRComployee(pageNum, pageSize, comploName, departName);
        return Result.success(pageInfo);
    }
    @Mylog(value = "通过ID查询员工")
    @GetMapping("/SelectById")
    public Result SelectById(Integer comploId){
        ComployeeInfoDto comployeeInfoDto = comployeeService.SelectById(comploId);
        return Result.success(comployeeInfoDto);
    }
    @Mylog(value = "插入员工")
    @PostMapping("/InsertComployee")
    public Result InsertComployee(@RequestBody Comployee comployee){
        comployeeService.InsertComployee(comployee);
        return Result.buildSuccess();
    }
    @Mylog(value = "修改员工的信息")
        @PostMapping("/UpdateComployee")
    public Result UpdateComployee(@RequestBody Comployee comployee){
        comployeeService.UpdateComployee(comployee);
        return Result.buildSuccess();
    }
    @Mylog(value = "重置员工密码")
    @PostMapping("/UpdatePassword")
    public Result UpdatePassword(Integer comploId,String comploPassword){
        comployeeService.UpdatePassword(comploId, comploPassword);
        return Result.buildSuccess();
    }
    @Mylog(value = "修改员工状态")
    @PostMapping("/UpdateStauts")
    public Result UpdateStauts(Integer comploStatus,Integer comploId){
        comployeeService.UpdateStauts(comploStatus, comploId);
        return Result.buildSuccess();
    }
    @GetMapping("/DeleteComployeeById")
    public Result DeleteComployeeById(Integer comploId){
        comployeeService.DeleteComployeeById(comploId);
        return Result.buildSuccess();
    }
}
